﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.Diagnostics;

namespace SMSAssistant.Model
{
    public class Emoji
    {

        public Emoji(int id,string imagePath,string tag,string name)
        {
            this.id = id;
            this.imagePath = imagePath;
            this.tag = tag;
            this.name = name;

            if (!string.IsNullOrEmpty(this.imagePath))
            {
                Deployment.Current.Dispatcher.BeginInvoke
                    (new Action<Emoji>((e) => { LoadImage(e); }), this);
            }
        }

        int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        string imagePath;

        public string ImagePath
        {
            get { return imagePath; }
            set
            {
                imagePath = value;
            }
        }

        BitmapImage image;

        public BitmapImage Image
        {
            get { return image; }
            set { image = value; }
        }

        string tag;

        public string Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public static void LoadImage(Emoji emoji)
        {
            if (emoji.ImagePath != null)
            {
                try
                {
                    var bitmap = new BitmapImage(new Uri(emoji.ImagePath, UriKind.Relative));
                    bitmap.CreateOptions = BitmapCreateOptions.BackgroundCreation;
                    emoji.Image = bitmap;
                }
                catch (Exception e)
                {
                    var ee = e;
                    Debug.WriteLine(ee);
                }
            }
        }
    }
}
